package com.brisk.web.controller.applet;

import com.ruoyi.applet.domain.AppletSite;
import com.ruoyi.applet.service.IAppletSiteService;
import com.brisk.common.annotation.Log;
import com.brisk.common.core.controller.BaseController;
import com.brisk.common.core.domain.AjaxResult;
import com.brisk.common.core.page.TableDataInfo;
import com.brisk.common.enums.BusinessType;
import com.brisk.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * appletSiteController
 *
 * @author PENGFEIDENG
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/applet/appletSite")
public class AppletSiteController extends BaseController {

    @Autowired
    private IAppletSiteService appletSiteService;


    /**
     * 查询appletSite列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appletSite:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletSite appletSite) {
        startPage();
        List<AppletSite> list = appletSiteService.selectAppletSiteList(appletSite);
        return getDataTable(list);
    }

    /**
     * 导出appletSite列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appletSite:export')")
    @Log(title = "appletSite", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletSite appletSite) {
        List<AppletSite> list = appletSiteService.selectAppletSiteList(appletSite);
        ExcelUtil<AppletSite> util = new ExcelUtil<AppletSite>(AppletSite.class);
        util.exportExcel(response, list, "appletSite数据");
    }

    /**
     * 获取appletSite详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:appletSite:query')")
    @GetMapping(value = "/{siteId}")
    public AjaxResult getInfo(@PathVariable("siteId") Long siteId) {
        return AjaxResult.success(appletSiteService.selectAppletSiteBySiteId(siteId));
    }

    /**
     * 新增appletSite
     */
    @PreAuthorize("@ss.hasPermi('applet:appletSite:add')")
    @Log(title = "appletSite", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletSite appletSite) {
        return toAjax(appletSiteService.insertAppletSite(appletSite));
    }

    /**
     * 修改appletSite
     */
    @PreAuthorize("@ss.hasPermi('applet:appletSite:edit')")
    @Log(title = "appletSite", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletSite appletSite) {
        return toAjax(appletSiteService.updateAppletSite(appletSite));
    }

    /**
     * 删除appletSite
     */
    @PreAuthorize("@ss.hasPermi('applet:appletSite:remove')")
    @Log(title = "appletSite", businessType = BusinessType.DELETE)
    @DeleteMapping("/{siteIds}")
    public AjaxResult remove(@PathVariable Long[] siteIds) {
        return toAjax(appletSiteService.deleteAppletSiteBySiteIds(siteIds));
    }

    /**
     * 获取下拉列表
     *
     * @author PengFei Deng
     * @date 2022/5/30 16:33
     */
    @GetMapping("getSite/SelectList")
    public AjaxResult getSiteSelectList() {
        return AjaxResult.success(appletSiteService.getSiteSelectList());
    }


    @GetMapping("/getSiteInfoCharPie")
    public AjaxResult getSiteInfoCharPie() {
        return AjaxResult.success(appletSiteService.getSiteInfoCharPie());
    }

}
